package cn.tedu.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;



public class JdbcUtil {
    
	public static  Connection getConn() throws Exception {
		//加载驱动
		Class.forName("com.mysql.jdbc.Driver");
		System.out.println("驱动加载成功");
		//建立连接
		String url="jdbc:mysql://localhost:3306/epidemic19?charaterEncoding=utf8";
		String user="root";
		String password="123456";
		Connection conn=DriverManager.getConnection(url,user,password);
		System.out.println(conn+"建立连接成功");
		return conn;
	}
	
	public static void release(Connection conn,PreparedStatement ps,ResultSet rs) {
		if(rs !=null) {	
		      try {
				rs.close();
			} catch (SQLException e) {
				// TODO: handle exception
				e.printStackTrace();
			}finally {
				rs=null;
			}
		
		} 
		if(ps !=null) {	
		      try {
				ps.close();
			} catch (SQLException e) {
				// TODO: handle exception
				e.printStackTrace();
			}finally {
				ps=null;
			}
		
		}
		  if(conn !=null) {	
		      try {
				conn.close();
			} catch (SQLException e) {
				// TODO: handle exception
				e.printStackTrace();
			}finally {
				conn=null;
			}
		
		}
	}
	
	
	
	
}




